import 'dart:math';
import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

///
/// [author]: liMing
/// [Date]: 2021-08-05  11:00
///
class PageWatermark extends StatefulWidget {
  @override
  _PageWatermarkState createState() => _PageWatermarkState();
}

class _PageWatermarkState extends State<PageWatermark> {
  String watermark='hello is used ';
  @override
  Widget build(BuildContext context) {
    return CupertinoApp(
     debugShowCheckedModeBanner: false,
      home: ListView(
        children: [
          WillPopScope(
            // onWillPop: ,
            child: SizedBox(
              height: 280,
              child: _buildItem(),
            ),
          ),
          SizedBox(
            height: 300,
            child: Row(
              children: [
                Expanded(child: _buildItem()),
                Expanded(child: _buildItem()),
              ],
            ),
          ),
          SizedBox(
            height: 220,
            child: _buildItem(),
          ),
        ],
      ),
    );
  }

  _buildItem() {
    return Stack(
      fit: StackFit.expand,
      children: [
        Padding(padding: EdgeInsets.all(2),
        child: CupertinoPopupSurface(
          child: ImageFiltered(
            imageFilter: ImageFilter.blur(
              sigmaX: watermark!=null?2:0,
              sigmaY: watermark!=null?2:0,
            ),
            child: Padding(
              padding: EdgeInsets.all(24),
              child: FlutterLogo(
                style: FlutterLogoStyle.horizontal,
              ),
            ),
          ),
        ),),
        if(watermark!=null)
          LayoutBuilder(builder: (context,constraints){
            return Center(
              child: SizedBox(
                width: constraints.biggest.shortestSide,
                height: constraints.biggest.shortestSide,
                child: Transform.rotate(angle: -pi /4 ,child: FittedBox(child: Text(watermark),),),
              ),
            );
          })
      ],
    );
  }
}
